﻿//去掉png图片的背景
function correctPNG(obj)
{
   if(navigator.appName!="Microsoft Internet Explorer") return;
   if (navigator.appVersion.indexOf("MSIE 7.0")>0) return;
    var img=obj;
    var LW=img.width;
    var LH=img.height;
    var imgName=img.src.toUpperCase();
    if(imgName.substring(imgName.length-3,imgName.length)=="PNG"){
        img.style.filter+="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+img.src+", sizingmethod=scale);"
        img.src="images/tran.gif";
        img.width=LW;
        img.height=LH;
    }
}

function setHome(obj)
{
   var url="http://"+document.location.host+"/";
   obj.style.behavior="url(#default#homepage)";
   obj.setHomePage(url);
}

function addToFav(name)
{
    url="http://"+document.location.host+"/";
    window.external.AddFavorite(url,name);
}

//去掉空白
function rtrim(str)
{
    return str.replace(/^\s+/,"");    
}
function ltrim(str)
{
    return str.replace(/\s+$/,"");    
}
function trim(str)
{
    return str.replace(/^\s+/,"").replace(/\s+$/,"");    
}

//字数统计
function wordcount(obj)
{
   var aa=obj;
   var n=0;
   if (aa.value=="" || aa.value==null) return n;
   for (i=0;i<aa.value.length;i++)
   {
     if(aa.value.charCodeAt(i)>127)
       n+=2;
     else n++;
    }
    return n;
}
//
function findobj(n, d) {
    var p,i,x; if(!d) d=document;
    if((p=n.indexOf("?"))>0 && parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for(i=0;!x && i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x && d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    return x;
}
function copycode(obj) {
    var rng = document.body.createTextRange();
    rng.moveToElementText(obj);
    rng.scrollIntoView();
    rng.select();
    rng.execCommand("Copy");
    rng.collapse(false);
}

function showbg(obj,num)
{
 if (num==1){obj.style.backgroundColor="#eeeeee";}
 else
 if (num==2){obj.style.backgroundColor="#ffffff";}
}

function changeBg(obj,clr)
{
  var wh=obj;
  if (wh==null) return;
  wh.style.backgroundColor=clr;
}

function sureit(str){
    if (confirm(str)) 
        return true;
    else return false;
}
//全选、反选、取消
function checkAll(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a[i].checked = true;
}

function checkNone(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a[i].checked = false;
}

function checkOthers(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  {
  if  ( a[i].checked == true)
        a[i].checked = false;
  else  a[i].checked=true;
  }
}
//str：选项框的名称; obj：表单名; url:提交地址;
function doSubmit(str,obj,url)
{
  var a = document.getElementsByName(str);
  var fm=obj;
  if (fm==null)return false;
  var n = 0;i=0;
  for (i=0;i<a.length;i++)
  {
      if (a[i].checked==true) n++;
   }
  if (n==0) return false;
  if (!confirm("确定要进行批量操作?"))return false;
  obj.action=url;
  obj.method="post";
  obj.target="_blank";
  obj.submit();
}
//弹出窗口系列
function suredel(url){
  if (confirm("确定要删除吗?")){
    window.open(url,"","top=5,left=5,width=25,height=25,scrollbars=no");
  }
  else  return false;
}
function smallwin(url){
  window.open(url,"","top=5,left=5,width=25,height=25,scrollbars=no");
}
function winopen(url){
  window.open(url,"","top=5,left=5,width=620,height=420,scrollbars=yes,resizable=yes");    
  return false;
}
function Mywindow(url,w,h){
  window.open(url,"","top=5,left=5,width="+w+",height="+h+",scrollbars=yes,resizable=yes");
}
function openfull(url){
  window.open(url,"","top=0,left=0,fullscreen=yes,scrollbars=yes");
}

function isemail(str)
{
    var re=/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/gi;
    return re.test(str);
}

function isurl(str)
{
   var re=/^[a-zA-z]+:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/;
   return re.test(str);
}

//FLASH显示 key==1 透明显示
function show_flash(filepath,w,h,key)
{
    if (/^\S+\.swf$/i.test(filepath)==false) return;
    document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0\" width=\""+w+"\" height=\""+h+"\">");
    document.writeln("  <param name=\"movie\" value=\""+filepath+"\" \/>");
    document.writeln("  <param name=\"quality\" value=\"high\" \/>");
    if (key==1){
		document.writeln("  <param name=\"wmode\" value=\"transparent\" \/>");
		document.writeln("  <embed src=\""+filepath+"\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" type=\"application\/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\" wmode=\"transparent\"><\/embed>");
	}
	else document.writeln("  <embed src=\""+filepath+"\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" type=\"application\/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\" ><\/embed>");
    document.writeln("<\/object>");
}

//自动选择广告显示的格式 
//链接和路径分隔符:$$ 记录之间分隔符:||
//key:1 在格式为swf时生效，表示透明播放
function showAdv(filePath,w,h,key)
{
    var linkpath,tmpArr;
    linkpath="";
    if (typeof(filePath)=="undefined") return;
    tmpArr=filePath.split("$$");
    if (tmpArr.length>1){
        linkpath=tmpArr[0]
        filePath=tmpArr[1]
    }
    if (/^\S+\.swf$/i.test(filePath)){
        document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0\" width=\""+w+"\" height=\""+h+"\">");
        document.writeln("  <param name=\"movie\" value=\""+filePath+"\" \/>");
        document.writeln("  <param name=\"quality\" value=\"high\" \/>");
        if (key==1){
			document.writeln("  <param name=\"wmode\" value=\"transparent\" \/>");
			document.writeln("  <embed src=\""+filePath+"\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" type=\"application\/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\" wmode=\"transparent\"><\/embed>");
		}
		else document.writeln("  <embed src=\""+filePath+"\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" type=\"application\/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\"><\/embed>");
        document.writeln("<\/object>");
        return;
    }
    if(/^\S+\.(gif|jpg|png)$/i.test(filePath)){
      if (linkpath!="")
      document.writeln("<a href=\""+linkpath+"\" target=\"_blank\"><img src=\""+filePath+"\" width=\""+w+"\" height=\""+h+"\" border=\"0\" \/><\/a>");
      else
      document.writeln("<img src=\""+filePath+"\" width=\""+w+"\" height=\""+h+"\" border=\"0\" \/>");
      return;
    }
}

//显示日期
function showDate()
{
    var tmp="";
    var date=new Date();
    var weekday=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
    tmp=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日"+"  "+weekday[date.getDay()];
    document.write(tmp);
}

function showDate_en()
{
    var tmp="";
    var date=new Date();
    var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    tmp=weekday[date.getDay()]+"&nbsp;&nbsp;"+date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear();
    document.write(tmp);
}
//修复友情链接
function fixlink(obj,tgt)
{
    var url;
    if (obj.tagName!="A") return false;
    if (obj.href=="") return false;
    if (obj.href.split(/[\/\/\/]/)[2]==document.URL.split(/[\/\/\/]/)[2]){
        obj.href="http:\/\/"+obj.href.split(/[\/|\/\/]/).reverse()[0];
    }
    obj.target=tgt;
}


//内容切换
function txt_filter(objID,content,delay,style)
{
    var delay=(/^\d+$/.test(delay)==false)?3:delay;
    var style=(/^\d+$/.test(style)==false)?Math.floor(Math.random()*23):style;
    var obj=document.getElementById(objID);
	if (document.all){
    obj.style.filter="revealTrans(duration="+delay+",transition="+style+")";
	obj.filters[0].Apply();
    obj.innerHTML=content;
    obj.filters[0].play();
	}
	else{
    obj.innerHTML=content;
	}
}
